//
//  myImageCell.m
//  MyFamily
//
//  Created by 陆洋 on 15/6/4.
//  Copyright (c) 2015年 maili. All rights reserved.
//

#import "myImageCell.h"
#import "UIImageView+WebCache.h"

@interface myImageCell()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;


@end
@implementation myImageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = WRGBColor(235, 240, 244);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifier = @"myselfImageCell";
    
    //缓存中取
    myImageCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    //创建
    if (!cell)
    {
        cell = [[myImageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    //cell.userInteractionEnabled = NO;  //不让用户点击
    return cell;
}

-(void)setCellValue:(NSString *)sendImage
{
    [super setCellValue:sendImage];

    UIImage *image = [UIImage imageNamed:@"chatto_bg_normal.png"];
    image = [image resizableImageWithCapInsets:(UIEdgeInsetsMake(image.size.height * 0.6, image.size.width * 0.4, image.size.height * 0.3, image.size.width * 0.4))];

    self.headImageView.image = [UIImage imageNamed:@"phone_tx.png"];

    if ([sendImage containsString:@"http://"]) {

        [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:sendImage] placeholderImage:[UIImage imageNamed:@"phone_defulimg.png"]];

    } else {

        self.bgImageView.image = [[UIImage alloc] initWithContentsOfFile:sendImage];
    }

//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        NSData *data = UIImageJPEGRepresentation(sendImage, 0.1);
//        UIImage *resultImage = [UIImage imageWithData:data];
//        dispatch_async(dispatch_get_main_queue(), ^{
//            self.bgImageView.image = resultImage;
//        });
//    });


}


@end
